//创建多个线程，每个线程执行一个IOContext

#ifndef IOCONTEXTPOOL_H 
#define IOCONTEXTPOOL_H 

#include <cstdint>
#include <vector>
#include <memory>
#include <thread>

#include <boost/asio.hpp>

class IOContextPool
{
public:
    using IOContext = boost::asio::io_context;
    using Work = boost::asio::io_context::work;
    using WorkPtr = std::unique_ptr<Work>;

    IOContextPool(const IOContextPool&) = delete;
    IOContextPool& operator=(const IOContextPool&) = delete;

    IOContext& GetIOContext();
    void stop();
    static IOContextPool& GetInstance();

private:
    IOContextPool(uint32_t threads = std::thread::hardware_concurrency());

private:
    std::vector<IOContext> m_contexts;
    std::vector<WorkPtr> m_works;
    std::vector<std::thread> m_threads;
    uint32_t m_index;
};

#endif	/* IOCONTEXTPOOL_H */
